package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @author guozh
 */
@Mapper
public interface DishMapper {
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 增加菜品
     *
     * @param dish 菜品数据
     */
    @AutoFill(value = OperationType.INSERT)
    void insertDish(Dish dish);

    /**
     * 分页查询
     *
     * @param dishPageQueryDTO 分页查询参数
     * @return Result<Page < Dish>>
     */
    Page<DishVO> selectPageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据主键查询菜品
     *
     * @param id id
     * @return Dish
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user from dish where id = #{id}")
    Dish selectDishById(Long id);

    /**
     * 根据主键删除菜品数据
     *
     * @param ids ids
     */
    void deleteById(List<Long> ids);

    /**
     * 修改菜品信息
     *
     * @param dish 菜品信息
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类查询
     *
     * @param dish 菜品数据
     * @return Result<List < Dish>>
     */
    List<Dish> selectCategoryId(Dish dish);

    /**
     * 根据套餐id查询菜品
     *
     * @param setmealId setmealId
     * @return List<Dish>
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);
}
